<?php
/**
 * Datetime functions
 *
 * @version 0.2a
 */

// No direct access
defined( "__DEENZO__" ) or die( "deenzo$" );  
 
function timestamp( $token, $date = "" ) {
	
	if ( !$date ) $date = date("Y-m-d H:i:s");
	
	$ly    = "/^(minute|hour|dai|week|month|year)ly$/";
	$every = "/^every (\d\.?\d?)? (minute|hour|day|week(end)?|month|year)s?/";
		
	$token = strtolower( $token );
		
	/* *LY Timestamp */
	if ( preg_match( $ly, $token, $match ) ) {
			
		if ( $match[1] == "dai" )
			$match[1]  = "day";
			
		return date( "Y-m-d H:i:s", strtotime( "$date +1 " . $match[1] ) );
		
	/* EVERY ( n ) Timestamp */
	} elseif ( preg_match( $every, $token, $match ) ) {
		
		/* Every n > 2 Period */
		if ( is_numeric( $match[1] ) ) {
			$n = $match[1]; $lapse = $match[2];
			
		/* Every N = 1 Period */
		} else {
			$n = 1; $lapse = $match[1];
		}
			
		/** Weekends are special lapse ( not present in this version ) */
			
		return date( "Y-m-d H:i:s", strtotime( "$date +$n $lapse" ) );
	}
		
	return false;
}  